package com.dylan.foundation;

public class MyThreadInterrupt extends Thread {
    private volatile static boolean on = false;  //开光 用来标志线程是否中断

    @Override
    public void run() {
        while(true){
//            if(Thread.currentThread().isInterrupted()){
//                System.out.println("Yes,I am interruted,but I am still running");
//                return;
//            }else{
//                System.out.println("not yet interrupted");
//            }

                int i=0;
                while (true) {
                    if (this.isInterrupted()) {
                        System.out.println("已经是停止状态了!退出!");
                        return ;
                    }
                    System.out.println("i=" + (i + 1));
                    i = i+1;
                }


        }
    }
    public static void main(String[] args) {
        try {
            MyThreadInterrupt myThread = new MyThreadInterrupt();
            myThread.start();
            Thread.sleep(1000);
            myThread.interrupt();
            System.out.println("---------------------main thread end -----------------");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
